﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLT_BLL;
using QLT_Public;

namespace GiaoDien
{
    public partial class frm_ThayDoiMK : DevExpress.XtraEditors.XtraForm
    {
        public frm_ThayDoiMK()
        {
            InitializeComponent();
        }
        NhanVien_BLL nhanVien_bll = new NhanVien_BLL();
        private void btnDongY_Click(object sender, EventArgs e)
        {
            NhanVien_Public nv = new NhanVien_Public();
            nv.TenDangNhap = txtTenDangNhap.Text;
            nv.MatKhau = txtMatKhauMoi.Text;
            DataTable dt = new DataTable();
            string sql = "select * from tbl_NhanVien where TenDangNhap='" + txtTenDangNhap.Text + "' and MatKhau='" + txtMatKhauCu.Text + "'";
            dt = nhanVien_bll.taoBang(sql);
            if (dt.Rows.Count > 0)
            {
                if (txtMatKhauMoi.Text == txtNhapLaiMK.Text)
                {
                    nhanVien_bll.doiMatKhau(nv, nv);
                    XtraMessageBox.Show("Đổi mật khẩu thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                    XtraMessageBox.Show("Mật khẩu mới không khớp nhau!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
                XtraMessageBox.Show("Sai tên đăng nhập hoặc mật khẩu!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            txtTenDangNhap.ResetText();
            txtMatKhauCu.ResetText();
            txtMatKhauMoi.ResetText();
            txtNhapLaiMK.ResetText();

        }

        private void txtTenDangNhap_Leave(object sender, EventArgs e)
        {
            if (txtTenDangNhap.Text == "")
                txtTenDangNhap.Focus();
        }

        private void txtMatKhauCu_Leave(object sender, EventArgs e)
        {
            if (txtMatKhauCu.Text == "")
                txtMatKhauCu.Focus();
        }

        private void txtMatKhauMoi_Leave(object sender, EventArgs e)
        {
            if (txtMatKhauMoi.Text == "")
                txtMatKhauMoi.Focus();
        }

        private void txtNhapLaiMK_Leave(object sender, EventArgs e)
        {
            if (txtNhapLaiMK.Text == "")
                txtNhapLaiMK.Focus();   
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            txtTenDangNhap.ResetText();
            txtMatKhauCu.ResetText();
            txtMatKhauMoi.ResetText();
            txtNhapLaiMK.ResetText();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}